package com.example.wechat;

import android.graphics.drawable.Drawable;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.request.target.ImageViewTarget;
import com.bumptech.glide.request.transition.Transition;

public abstract class ProgressTarget<Z> extends ImageViewTarget<Z> {
    private int currentProgress = 0;

    public ProgressTarget(ImageView view) {
        super(view);
    }

    @Override
    public void onLoadStarted(@Nullable Drawable placeholder) {
        super.onLoadStarted(placeholder);
        currentProgress = 0;
        onProgress(0);
    }

    @Override
    public void onLoadFailed(@Nullable Drawable errorDrawable) {
        super.onLoadFailed(errorDrawable);
        onProgress(0);
    }

    @Override
    public void onResourceReady(@NonNull Z resource, @Nullable Transition<? super Z> transition) {
        super.onResourceReady(resource, transition);
        onProgress(100);
    }

    public void onProgress(int progress) {
        if (currentProgress != progress) {
            currentProgress = progress;
            onProgressUpdate(progress);
        }
    }

    protected abstract void onProgressUpdate(int progress);
} 